//
//  HYLPicAndText.m
//  绘制图片和文字
//
//  Created by hyl on 16/6/26.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "HYLPicAndText.h"

@implementation HYLPicAndText

#pragma mark - drawRect
- (void)drawRect:(CGRect)rect {
//    [self drawImage:rect];
//    [self drawImage2:rect];
//    [self drawImage3:rect];
    [self drawText:rect];
    
}

#pragma mark - 小黄人
-(void) drawImage:(CGRect) rect{
    UIImage *image=[UIImage imageNamed:@"黄人"];
    //图片有可能显示不全，因为绘制的图片与实际所给图片一样大
    //    [image drawAtPoint:CGPointZero];
    //将整个图片放置到view中显示
    [image drawInRect:rect];
}

#pragma mark - 花图
-(void) drawImage2:(CGRect) rect{
    UIImage *image=[UIImage imageNamed:@"001"];
    //平铺
    [image drawAsPatternInRect:rect];
}

#pragma mark - 花图裁切
-(void) drawImage3:(CGRect) rect{
    UIImage *image=[UIImage imageNamed:@"001"];
    UIRectClip(CGRectMake(0, 0, 50, 50));
    //平铺
    [image drawAsPatternInRect:rect];
}

#pragma mark - 绘制文字
-(void) drawText:(CGRect) rect{
    
    NSString *str=@"绘制文字sssssssssssssssssssssssssssssssss";
    
    NSMutableDictionary *textDic=[NSMutableDictionary dictionary];
    textDic[NSFontAttributeName]=[UIFont systemFontOfSize:30];
    textDic[NSForegroundColorAttributeName]=[UIColor redColor];
    textDic[NSStrokeWidthAttributeName]=@3;
    //// UIColor, default nil: same as foreground color
    textDic[NSStrokeColorAttributeName]=[UIColor blueColor];
    NSShadow *shade=[[NSShadow alloc]init];
    shade.shadowBlurRadius=1;
    shade.shadowColor=[UIColor redColor];
    shade.shadowOffset=CGSizeMake(2, 2);
    textDic[NSShadowAttributeName]=shade;
    //这个不会换行
//    [str drawAtPoint:CGPointZero withAttributes:textDic];
    [str drawInRect:rect withAttributes:textDic];
}

@end
